﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HRMS_Model;
using System.Diagnostics;

namespace HRMS.Models
{
    public class AttendancesModels
    {

        public static bool AddAttendance(Attendance attendance)
        {
            try
            {
                using (var attEntity = new HRMSEntities())
                {
                    attEntity.Attendances.AddObject(attendance);
                    attEntity.SaveChanges();
                    return true;
                }
            }
            catch (Exception ex)
            {
                Debug.Write(ex.Message);
                return false;
            }

        }
        public static List<Attendance> GetAttendances(string sortExpression, string sortDirection, int pageIndex, int pageSize, int pageCount)
        {
            using (var attEntity = new HRMSEntities())
            {
                return attEntity.Attendances.OrderBy("it." + sortExpression + " " + sortDirection).Skip(pageIndex * pageSize).Take(pageCount * pageSize).ToList();
            }
        }


        public static int GetAttendancesCount()
        {
            using (var attendanceEntity = new HRMSEntities())
            {
                return attendanceEntity.Attendances.Count();
            }
        }
    }
}
